// mapper/UserMapper_wxt.java
package com.scuec.groupfive.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.Map;

@Mapper
public interface UserMapper_wxt {

    // 总注册用户数
    @Select("SELECT COUNT(*) AS total FROM users")
    Long countTotalUsers();

    // 按自定义时间维度统计
    @Select({
            "<script>",
            "SELECT COUNT(*) FROM users",
            "WHERE 1=1",
            "<when test='type == \"day\"'> AND DATE(created_at) = #{value} </when>",
            "<when test='type == \"week\"'> AND YEARWEEK(created_at, 1) = #{value} </when>", // 直接匹配数值
            "<when test='type == \"month\"'> AND DATE_FORMAT(created_at, '%Y-%m') = #{value} </when>",
            "<when test='type == \"year\"'> AND YEAR(created_at) = #{value} </when>",
            "</script>"
    })
    Long countByCustomTimeRange(@Param("type") String type, @Param("value") String value);
}